package model;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@NoArgsConstructor
@AllArgsConstructor
@Data
public class Goods implements java.io.Serializable {
	private String id;
	private String goodsname;
	private String goodsstyle;
	private String price;
	private String surplus;
	private String picAddress;

	/**
	 * 购买商品。
	 * @param number 要购买的数量
	 * @return 是否购买成功
	 */
	public boolean buyGood(String number){
		if(Integer.parseInt(surplus) < Integer.parseInt(number)){
			//余量小于要购买的数量，购买失败
			return false;
		} else{
			int sur = Integer.parseInt(surplus) - Integer.parseInt(number);
			surplus = String.valueOf(sur);
			return true;
		}
	}
	}